package com.ruoyi.langchain4j.config;

import com.ruoyi.langchain4j.store.MongoChatMemoryStore;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description:
 * @author: lizhihua
 * @date: 2025/6/8
 */
@Configuration
public class SeparateChatAssistantConfig {

    @Autowired
    private MongoChatMemoryStore  mongoChatMemoryStore;

    /**
     * .chatMemoryStore 指定聊天记录存储方式
     * 系统自带的两种 new InMemoryChatMemoryStore(),new SingleSlotChatMemoryStore()
     * 默认为:new SingleSlotChatMemoryStore()
     * .chatMemoryStore(mongoChatMemoryStore)使用mongo存储聊天
     */

    @Bean
    public ChatMemoryProvider chatMemoryProvider() {
        return memoryId -> MessageWindowChatMemory
                .builder()
                .id(memoryId)
                .maxMessages(10)
                .chatMemoryStore(mongoChatMemoryStore)
                .build();
    }
}
